﻿<!DOCTYPE html>
<html>
<body>
  数据：<input></input><button>获取</button>
  <script>
  document.querySelector('button').addEventListener('click',function(e){
    e.preventDefault();
    var xhr = new XMLHttpRequest();
    if(typeof xhr.withCredentials === undefined){
      console.log("浏览器不支持html5 XMLHttpRequest Level 2的跨源请求支持");
    }else{
      xhr.onload = function(){
        var data =JSON.parse(xhr.responseText)
        document.querySelector('input').value = data.data;
      };
      xhr.onerror = function(e){
        console.log(e)
      };
      xhr.open("GET", "http://localhost:8080/", true);  
      xhr.send();  
    };
  });
  </script>
</body>
</html>